import axios from 'axios'

export const request = axios.create({
    baseURL: 'https://conduit.productionready.io'
})

// 通过插件机制获取 store
export default ({store})=>{
    request.interceptors.request.use(config => {
        const {user} = store.state
        if(user && user.token){
            config.headers.Authorization = `Token ${user.token}`
        }
        return config
    }, error => {
        // 没发送就失败了
        return Promise.reject(error)
    })
}